<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<form class="" action="" method="post" >
	<p>用户名:<input type="text" value="" /> </p>
	<p> 邮箱:<input type="text" value="" /> </p>
	<p> 密码:<input type="text" value="" /></p>
	<p> 重复密码:<input type="text" value="" /> </p>
	<input type="submit" name="name" value="提交" />
	</form>
</body>
	<script type="text/javascript">
		var fm = document.getElementsByTagName('form')[0];

	fm.onsubmit =function(){
		var inp = document.getElementsByTagName('input');
		var name = /^\w{4,16}$/;
		if(!name.test(inp[0].value)){
			alert('用户名不对!');
			return false;
		}

		var email = /^\w+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9]+)+/;
		if(!email.test(inp[1].value)){
			alert('邮箱不对!');
			return false;
		}

		if(inp[2].value.length < 6){
			alert('不够长');
			return false;
		}

		if(inp[2].value.length != inp[3].value.length){
			alert('密码不对!');
			return false;
		}
	}

	</script>
</html>